package com.power.sifa.approve.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.plf.common.domain.PageDataResponse;
import com.power.sifa.approve.dao.Apl_admreviewDao;
import com.power.sifa.approve.model.Apl_arrive_main;
import com.power.sifa.approve.model.pageInfo.Apl_admreviewPageInfo;
import com.power.sifa.approve.service.Apl_arrive_mainService;
import com.power.sifa.supervise.dao.Apl_superviseDao;
import com.power.sifa.supervise.model.pageInfo.Apl_supervisePageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiongzhiwen
 * @version 1.0
 * @description: TODO
 * @date 2024/3/25 22:37
 */
@Service
@RequiredArgsConstructor
public class Apl_arrive_mainServiceImpl implements Apl_arrive_mainService {


    private final Apl_admreviewDao apl_admreviewDao;


    private final Apl_superviseDao apl_superviseDao;


    @Override
    public PageDataResponse queryArriveData(Apl_admreviewPageInfo pageInfo) {
        List<Apl_arrive_main> list = apl_admreviewDao.queryArriveData(pageInfo);
        // 分页
        PageDataResponse page = new PageDataResponse();
        if (CollectionUtil.isNotEmpty(list)) {
            for (Apl_arrive_main data : list) {
                data.geneText();
            }
            Long total = Long.valueOf(pageInfo.getAllcount());
            int size = pageInfo.getPageSize() * pageInfo.getPageNumber();
            if (total.intValue() - size > 0) {
                page.setNextPage(pageInfo.getPageNumber() + 1);
            }
            page.setSize(pageInfo.getPageSize());
            page.setCurrent(pageInfo.getPageNumber());
            page.setTotal(total);
        } else {
            page.setSize(0);
            page.setCurrent(1);
            page.setTotal(0L);
        }
        page.setRecords(list);
        return page;
    }

    @Override
    public PageDataResponse querySuperviseArriveData(Apl_supervisePageInfo pageInfo) {
        List<Apl_arrive_main> list = apl_superviseDao.querySuperviseArriveData(pageInfo);
        // 分页
        PageDataResponse page = new PageDataResponse();
        if (CollectionUtil.isNotEmpty(list)) {
            for (Apl_arrive_main data : list) {
                data.geneText();
            }
            Long total = Long.valueOf(pageInfo.getAllcount());
            int size = pageInfo.getPageSize() * pageInfo.getPageNumber();
            if (total.intValue() - size > 0) {
                page.setNextPage(pageInfo.getPageNumber() + 1);
            }
            page.setSize(pageInfo.getPageSize());
            page.setCurrent(pageInfo.getPageNumber());
            page.setTotal(total);
        } else {
            page.setSize(0);
            page.setCurrent(1);
            page.setTotal(0L);
        }
        page.setRecords(list);
        return page;
    }
}
